/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.core.web.tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import org.merak.core.web.mvc.FrontController;
import org.merak.core.web.mvc.MVCManager;

@SuppressWarnings("serial")
public class Anchor extends TagSupport  {

    //~ Attributes ///////////////////////////////////////////////////////////////
	//****************************************************************************
	private String business = null;
	private String params   = null;
	private String charset  = null;
	private String coords   = null;
	private String hreflang = null;
	private String name     = null;
	private String rel      = null;
	private String rev      = null;
	private String shape    = null;
	private String target   = null;
	private String clazz    = null;

	//~ Constructors /////////////////////////////////////////////////////////////
	//****************************************************************************
	public Anchor() {
		super();
	}

    //~ Methods //////////////////////////////////////////////////////////////////
	//****************************************************************************
	@Override
	public int doStartTag() throws JspException {

		try {
			// Mandatory attributes
			StringBuffer buffer = new StringBuffer()
			.append("<a href='")
			.append(FrontController.getName())
			.append('?')
			.append(MVCManager.getBusinessParameter())
			.append('=')
			.append(this.business);

			// Special Optional Attributes
			if (this.params != null) {
				buffer.append('&').append(this.params);
			}
			buffer.append('\'');

			// Optional attributes
			if (this.getTarget()  !=null) buffer.append(" target='").append(this.getTarget()).append('\'');
			if (this.getId()      !=null) buffer.append(" id='").append(this.getId()).append('\'');
			if (this.getClazz()   !=null) buffer.append(" class='").append(this.getClazz()).append('\'');
			if (this.getName()    !=null) buffer.append(" name='").append(this.getName()).append('\'');
			if (this.getCharset() !=null) buffer.append(" charset='").append(this.getCharset()).append('\'');
			if (this.getCoords()  !=null) buffer.append(" coords='").append(this.getCoords()).append('\'');
			if (this.getHreflang()!=null) buffer.append(" hreflang='").append(this.getHreflang()).append('\'');
			if (this.getRel()     !=null) buffer.append(" rel='").append(this.getRel()).append('\'');
			if (this.getRev()     !=null) buffer.append(" rev='").append(this.getRev()).append('\'');
			if (this.getShape()   !=null) buffer.append(" shape='").append(this.getShape()).append('\'');

			// Render the tag
			buffer.append(">");
			this.pageContext.getOut().write(buffer.toString());
		}
		catch(IOException e) {
			throw new JspTagException("IO Error: " + e.getMessage());
		}
		return Tag.EVAL_BODY_INCLUDE;

	}
	//****************************************************************************
	@Override
	public int doEndTag() throws JspException {

		try {
			this.pageContext.getOut().write("</a>");
		}
		catch(IOException e) {
			throw new JspTagException("IO Error: " + e.getMessage());
		}
		return EVAL_PAGE;

	}
	//****************************************************************************
	public String getParams() {
		return this.params;
	}
	//****************************************************************************
	public void setParams(String params) {
		this.params = params;
	}
	//****************************************************************************
	public String getClazz() {
		return this.clazz;
	}
	//****************************************************************************
	public void setClazz(String clazz) {
		this.clazz = clazz;
	}
	//****************************************************************************
	public String getBusiness() {
		return this.business;
	}
	//****************************************************************************
	public void setBusiness(String business) {
		this.business = business;
	}
	//****************************************************************************
	public String getCharset() {
		return this.charset;
	}
	//****************************************************************************
	public String getCoords() {
		return this.coords;
	}
	//****************************************************************************
	public String getHreflang() {
		return this.hreflang;
	}
	//****************************************************************************
	public String getName() {
		return this.name;
	}
	//****************************************************************************
	public String getRel() {
		return this.rel;
	}
	//****************************************************************************
	public String getRev() {
		return this.rev;
	}
	//****************************************************************************
	public String getShape() {
		return this.shape;
	}
	//****************************************************************************
	public String getTarget() {
		return this.target;
	}
	//****************************************************************************
	public void setCharset(String charset) {
		this.charset = charset;
	}
	//****************************************************************************
	public void setCoords(String coords) {
		this.coords = coords;
	}
	//****************************************************************************
	public void setHreflang(String hreflang) {
		this.hreflang = hreflang;
	}
	//****************************************************************************
	public void setName(String name) {
		this.name = name;
	}
	//****************************************************************************
	public void setRel(String rel) {
		this.rel = rel;
	}
	//****************************************************************************
	public void setRev(String rev) {
		this.rev = rev;
	}
	//****************************************************************************
	public void setShape(String shape) {
		this.shape = shape;
	}
	//****************************************************************************
	public void setTarget(String target) {
		this.target = target;
	}
	//****************************************************************************
}
